package com.insuremonitor.web.controller.system;

import java.util.List;
import java.util.Set;

import com.insuremonitor.common.core.domain.entity.MonitorUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.insuremonitor.common.constant.Constants;
import com.insuremonitor.common.core.domain.AjaxResult;
import com.insuremonitor.common.core.domain.model.LoginBody;
import com.insuremonitor.common.utils.SecurityUtils;
import com.insuremonitor.framework.web.service.SysLoginService;

/**
 * 登录验证
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/monitor")
public class SysLoginController
{
    @Autowired
    private SysLoginService loginService;


    /**
     * 登录方法
     * 
     * @param loginBody 登录信息
     * @return 结果
     */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginBody loginBody)
    {
        AjaxResult ajax = AjaxResult.success();
        // 生成令牌
        String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
                loginBody.getUuid());
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }

    /**
     * 获取用户信息
     * 
     * @return 用户信息
     */
    @GetMapping("getInfo")
    public AjaxResult getInfo()
    {
        MonitorUser user = SecurityUtils.getLoginUser().getMonitorUser();

        AjaxResult ajax = AjaxResult.success();
        ajax.put("user", user);

        return ajax;
    }





}
